import 'package:flutter/material.dart';
import 'package:x3_charts_core/chart_painter/cobweb_chart_painter.dart';
import 'package:x3_charts_core/model/cob_web_chart_data_model.dart';

///**
///* @author hrongyong
///* @date   1/26/21
///* @email hrongyong@gmail.com
///* Description: 蛛网图组件
///*/
class CobwebChartWidget extends StatefulWidget {
  final List<CobwebChartDataModel> cobwebList;

  final int sideNum;

  ///遮罩画笔的填充颜色
  final Color color;

  ///遮罩层的描边颜色
  /// final Color strokeColor;

  CobwebChartWidget({@required this.cobwebList, this.color, this.sideNum = 5});

  @override
  _CobwebChartWidgetState createState() => _CobwebChartWidgetState();
}

class _CobwebChartWidgetState extends State<CobwebChartWidget> {
  Color get fillColor => widget.color ?? Color(0xFF90CD93);
  Color get strokeColor => fillColor.withAlpha(95);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(top: 10),
      alignment: Alignment.center,
      child: LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
          return Center(
            child: CustomPaint(
              size: Size(constraints.maxWidth, constraints.maxHeight),
              painter: CobwebChartPainter(
                sideNum: widget.sideNum,
                cobwebList: widget.cobwebList,
                fillColor: fillColor,
                strokeColor: strokeColor,
              ),
            ),
          );
        },
      ),
    );
  }
}
